package com.library.util.poi;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import com.library.entity.RBookCar;
import com.library.entity.dto.BookCarDto;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;

import java.util.List;

/**
 * 实施进度报表 拦截器
 * <p> 参考：https://www.cnblogs.com/better-farther-world2099/articles/16106085.html </p>
 * @author
 * @date 2024/9/19 星期四
 * @since JDK 17
 */
public class ImplProgressReportSheetWriteHandler implements SheetWriteHandler {

    private BookCarDto dto;

    public ImplProgressReportSheetWriteHandler(BookCarDto dto) {
        this.dto = dto;
    }

    @Override
    public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {

    }

    @Override
    public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
        Workbook workbook = writeWorkbookHolder.getWorkbook();
        Sheet sheet = workbook.getSheetAt(0);
        // 设置第一行标题
        Row row1 = sheet.createRow(0);
       // row1.setHeight((short) 200);
        Cell row1Cell1 = row1.createCell(0);
        row1Cell1.setCellValue("河南省2024农家书屋书单");
        Row row2 = sheet.createRow(1);
        //row2.setHeight((short) 200);
        Cell row1Cell2 = row2.createCell(0);
        row1Cell2.setCellValue("地址："+dto.getAddressName()+dto.getAddressDetail() +"联系人："+dto.getLinkMan()+"电话："+dto.getLinkPhone());
        CellStyle row1CellStyle = workbook.createCellStyle();
        row1CellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        row1CellStyle.setAlignment(HorizontalAlignment.CENTER);
        Font row1Font = workbook.createFont();
        row1Font.setBold(true);
        row1Font.setFontName("方正小标宋_GBK");
        row1Font.setFontHeightInPoints((short) 15);
        row1CellStyle.setFont(row1Font);
        row1Cell1.setCellStyle(row1CellStyle);
        //合并单元格，起始行,结束行,起始列,结束列
        sheet.addMergedRegionUnsafe(new CellRangeAddress(0, 0, 0, 7));
        sheet.addMergedRegionUnsafe(new CellRangeAddress(1, 1, 0, 7));
    }
}